package com.hzsai.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * 多数据源配置方式1
 *
 */
@Configuration
public class DataSourceConfig {

    @Bean(name = "springbootDS")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.first")
    public DataSource dataSource1() {
        DataSource ds1 =  DataSourceBuilder.create().build();
        System.out.println("Configuration DS springbootDS.");
        System.out.println(ds1.toString());
        return ds1;
    }

    @Bean(name = "sakilaDS")
    @ConfigurationProperties(prefix = "spring.datasource.second")
    public DataSource dataSource2() {
        DataSource ds2 = DataSourceBuilder.create().build();
        return ds2;
    }

    @Bean(name = "springbootDS_e1")
    @ConfigurationProperties(prefix = "spring.datasource.third")
    public DataSource datasource3() {
        DataSource ds3 = DataSourceBuilder.create().build();
        return ds3;
    }

    @Bean(name = "sakilaDS_e1")
    @ConfigurationProperties(prefix = "spring.datasource.fouth")
    public DataSource dataSource4() {
        DataSource ds4 = DataSourceBuilder.create().build();
        return ds4;
    }
}
